package cn.sccdlg.spring5.jdbctemplate.jdbctemplate;

import cn.sccdlg.spring5.jdbctemplate.dao.IAccountDao;
import cn.sccdlg.spring5.jdbctemplate.domain.Account;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * @author RaoShuang
 * @emil 991207823@qq.com
 * @date 2020/10/20 23:27
 * JdbcTemplate的最基本用法
 *  操作dao层实现实例，进行CRUD
 */
public class JdbcTemplateDemo4 {

    public static void main(String[] args) {
        //1.获取容器
        ApplicationContext ac = new ClassPathXmlApplicationContext("bean.xml");
        //2.获取对象
        IAccountDao accountDao = ac.getBean("accountDao",IAccountDao.class);

        Account account = accountDao.findAccountById(1);
        System.out.println("开始前：" + account);

        account.setMoney(30000f);
        accountDao.updateAccount(account);

        Account account2 = accountDao.findAccountById(1);
        System.out.println("更新后：" + account2);
    }

    @Test
    public void testFindAccountByName() {
        //1.获取容器
        ApplicationContext ac = new ClassPathXmlApplicationContext("bean.xml");
        //2.获取对象
        IAccountDao accountDao = ac.getBean("accountDao2",IAccountDao.class);
        Account account = accountDao.findAccountByName("eee");
        System.out.println("eee账户信息：" + account);
    }
}
